// pages/subscribe/subscribe.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    index:0,
    index1: 0,    
    items: [
      { name: 'USA', value: '男' },
      { name: 'CHN', value: '女', checked: 'true' },
    ],
    areas:'',
    types:'',
    array: ['本地兼职', '外地兼职'],
    area: ['免费兼职', '收费兼职'],
    publics: [
      { name: 'USA', value: '高薪', checked: 'true' },
      { name: 'CHN', value: '最热', },
      { name: 'BRA', value: '轻松', },
      { name: 'JPN', value: '日结', },
    ]
    
  },
  radioChange: function (e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  bindPickerChange: function (e) {
    var arrays=this.data.array;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value,
      areas: arrays[e.detail.value]
    })
  },
  bindPickerChange1: function (e) {
    var arrays = this.data.area;
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index1: e.detail.value,
      types: arrays[e.detail.value]
    })
  },
  submit: function (e) {
    var that = this;
    var areas = that.data.areas;
    let suc = false;
    wx.request({
      url: app.data.Url + 'login/getUser1',
      data: {
        user: wx.getStorageSync('uid'),
      },
      method: "post",
      success: function (res) {
        if (res.data == 0) {
          wx.navigateTo({
            url: '../editor/editor'
          })
        } else {
          if (areas == false) {
            areas = that.data.array[0];
          }
          var types = that.data.types;
          if (types == false) {
            types = that.data.area[0];
          }
          var sex = e.detail.value.sex;
          var others = e.detail.value.other;
          var usid = wx.getStorageSync("usid");
          wx.request({
            url: 'https://www.135k.com/addons/sd_humans/tp/index.php/subscribe/subscribe',
            data: {
              usid: usid,
              sex: sex,
              range: areas,
              area: types,
              others: JSON.stringify(others)
            },
            method: "post",
            dataType: "json",
            success: function (res) {
              setTimeout
              wx.showToast({
                title: '订阅成功 ！',
                icon: 'none',
                duration: 1500
              })
              setTimeout(function () {//确认之后跳转的页面
                wx.switchTab({
                  url: '../my/my'
                })
              }, 1500);
            }
          })
        }
      }
    });

    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})